<template>
  <div>
    <p class="tip">
      <span>Warning 1：动态行高与虚拟滚动的取舍，通过关闭高性能的虚拟滚动可以支持动态行高</span><br>
      <span class="red">（注：如果是通过任意方式去动态改变行高，使用这个方式的所有兼容问题都应该自行处理）</span>
    </p>

    <vxe-table
      border
      resizable
      height="400"
      :data="tableData"
      :scroll-x="{enabled: false}"
      :scroll-y="{enabled: false}">
      <vxe-table-column type="seq" width="80" fixed="left"></vxe-table-column>
      <vxe-table-column field="name" title="Name">
        <template v-slot="{ row, rowIndex }">
          <template v-if="rowIndex % 4 === 0">
            <div>{{ row.name }}</div>
            <div style="color: red">{{ row.age }}</div>
            <div>{{ row.role }}</div>
          </template>
          <template v-else-if="rowIndex % 3 === 0">
            <img src="https://n.sinaimg.cn/sinacn17/w120h120/20180314/89fc-fyscsmv5911424.gif" style="width: 60px;">
          </template>
          <template v-else>
            <span>{{ row.name }}</span>
          </template>
        </template>
      </vxe-table-column>
      <vxe-table-column field="sex" title="Sex"></vxe-table-column>
      <vxe-table-column field="age" title="Age">
        <template v-slot="{ row, rowIndex }">
          <template v-if="rowIndex % 5 === 0">
            <img src="https://pic2.zhimg.com/50/v2-f7031359103859e1ed38559715ef5f3f_hd.gif" style="width: 60px;">
          </template>
          <template v-else>
            <span>{{ row.age }}</span>
          </template>
        </template>
      </vxe-table-column>
      <vxe-table-column field="role" title="Role"></vxe-table-column>
    </vxe-table>

    <p class="demo-code">{{ $t('app.body.button.showCode') }}</p>

    <pre>
      <code class="xml">{{ demoCodes[0] }}</code>
      <code class="javascript">{{ demoCodes[1] }}</code>
    </pre>
  </div>
</template>

<script>
import hljs from 'highlight.js'

export default {
  data () {
    return {
      tableData: [],
      demoCodes: [
        `
        <vxe-table
          border
          resizable
          height="400"
          :data="tableData"
          :scroll-x="{enabled: false}"
          :scroll-y="{enabled: false}">
          <vxe-table-column type="seq" width="80" fixed="left"></vxe-table-column>
          <vxe-table-column field="name" title="Name">
            <template v-slot="{ row, rowIndex }">
              <template v-if="rowIndex % 4 === 0">
                <div>{{ row.name }}</div>
                <div style="color: red">{{ row.age }}</div>
                <div>{{ row.role }}</div>
              </template>
              <template v-else-if="rowIndex % 3 === 0">
                <img src="https://n.sinaimg.cn/sinacn17/w120h120/20180314/89fc-fyscsmv5911424.gif" style="width: 60px;">
              </template>
              <template v-else>
                <span>{{ row.name }}</span>
              </template>
            </template>
          </vxe-table-column>
          <vxe-table-column field="sex" title="Sex"></vxe-table-column>
          <vxe-table-column field="age" title="Age">
            <template v-slot="{ row, rowIndex }">
              <template v-if="rowIndex % 5 === 0">
                <img src="https://pic2.zhimg.com/50/v2-f7031359103859e1ed38559715ef5f3f_hd.gif" style="width: 60px;">
              </template>
              <template v-else>
                <span>{{ row.age }}</span>
              </template>
            </template>
          </vxe-table-column>
          <vxe-table-column field="role" title="Role"></vxe-table-column>
        </vxe-table>
        `,
        `
        export default {
          data () {
            return {
              tableData: []
            }
          },
          created () {
            this.tableData = window.MOCK_DATA_LIST.slice(0, 200)
          }
        }
        `
      ]
    }
  },
  created () {
    this.tableData = window.MOCK_DATA_LIST.slice(0, 200)
  },
  mounted () {
    Array.from(this.$el.querySelectorAll('pre code')).forEach((block) => {
      hljs.highlightBlock(block)
    })
  }
}
</script>
